﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Jalal.Library.Data;
using System.Data.Common;
using Jalal.Library.Utility;

namespace BCGC.DAL
{
    public class CMSData
    {
        public static DataTable GetCMSById(int cmsId)
        {
            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();
            command.CommandText = "CSP_GetCMSById";
            dataMiner.AddParameter(command, "@CmsId", DbType.Int32, 0, ParameterDirection.Input, cmsId);
            return dataMiner.GetListData(command);
        }

        public static int UpdateCMSData(int cmsId, string cmsTitle, string cmsContent, DateTime lastUpdate)
        {
            object count = null;
            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();
            command.CommandText = "CSP_UpdateCMS";
            dataMiner.AddParameter(command, "@CmsId", DbType.Int32, 0, ParameterDirection.Input, cmsId);
            dataMiner.AddParameter(command, "@CmsTitle", DbType.String, 500, ParameterDirection.Input, cmsTitle);
            dataMiner.AddParameter(command, "@CmsContent", DbType.String, -1, ParameterDirection.Input, cmsContent);
            dataMiner.AddParameter(command, "@LastUpdate", DbType.DateTime, 0, ParameterDirection.Input, lastUpdate);
            dataMiner.AddParameter(command, "ReturnValue", DbType.Int32, 0, ParameterDirection.ReturnValue, null);
            dataMiner.Execute(command, out count);

            return (int)CommonUtility.FilterNull(count, typeof(int));
        }
    }
}
